package com.neymar.controller;


import com.neymar.entity.Position;
import com.neymar.entity.User;
import com.neymar.logEnum.ObjectionTypeEnum;
import com.neymar.service.LogService;
import com.neymar.service.PositionService;
import com.neymar.service.UserService;
import com.neymar.vo.PositionVO;
import com.neymar.vo.R;
import com.neymar.vo.RecruiterVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 求职者表 前端控制器
 * </p>
 *
 * @author neymar
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/position")
@Api(tags = {"岗位信息操作接口"})
public class PositionController {
    @Autowired
    private PositionService positionService;

    @Autowired
    private LogService logService;

    @ApiOperation("保存岗位信息")
    @PostMapping("/save/{userId}")
    public R save(@RequestBody Position position,
                  @PathVariable("userId") String userId) {
        int flag = positionService.save(position);
        if (flag != 0) {
            logService.save(userId, 1, 2);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("根据岗位ID查询岗位信息")
    @GetMapping("/find/{userId}")
    public R findPosition(@RequestBody Position position,
                          @PathVariable("userId") String userId) {
        logService.save(userId, 4, 2);
        return R.ok(positionService.findPosition(position));
    }

    @ApiOperation("根据岗位ID删除岗位信息")
    @DeleteMapping("/delete/{positionId}/{userId}")
    public R deletePositionById(@PathVariable("positionId") String positionId,
                                @PathVariable("userId") String userId) {
        int flag = positionService.deletePositionById(positionId);
        if (flag != 0) {
            logService.save(userId, 2, 2);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("根据岗位ID修改岗位信息")
    @PutMapping("/update/{userId}")
    public R updatePositionById(@RequestBody Position position,
                                @PathVariable("userId") String userId) {
        int flag = positionService.updatePositionById(position);
        if (flag != 0) {
            logService.save(userId, 3, 2);
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("查看岗位数量信息")
    @GetMapping("/showNumInfo")
    public R positionNumber() {
        int flag = positionService.positionNumber();
        if (flag != 0) {
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("查看不同类型岗位的数量")
    @GetMapping("/showTypeInfo/{operatorId}")
    public R showTypeInfo(@PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 2);
        return R.ok(positionService.showTypeInfo());
    }

    @ApiOperation("查看所有的岗位薪水分布情况")
    @GetMapping("/showSalaryInfo/{operatorId}")
    public R showSalaryInfo(@PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 2);
        return R.ok(positionService.showSalaryInfo());
    }


    @ApiOperation("[分页查询] 根据[名字][类型]模糊查询岗位")
    @GetMapping("/findPositions/{current}/{size}/{type}/{name}/{operatorId}")
    public R findRecruiters(@PathVariable("current") int current,
                            @PathVariable("size") int size,
                            @PathVariable("type") String type,
                            @PathVariable("name") String name,
                            @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 2);
        return R.ok(positionService.findAllPosition(current, size, type, name));
    }

    @ApiOperation("[分页查询] 根据[名字][类型]模糊查询岗位详细信息[包含发布者的详细信息]")
    @GetMapping("/findPositionDetails/{current}/{size}/{type}/{name}/{operatorId}")
    public R findRecruitersDetails(@PathVariable("current") int current,
                                   @PathVariable("size") int size,
                                   @PathVariable("type") String type,
                                   @PathVariable("name") String name,
                                   @PathVariable("operatorId") String operatorId) {
        logService.save(operatorId, 4, 2);
        return R.ok(positionService.findAllPositionDetails(current, size, type, name));
    }


}

